﻿Imports System.Reflection

<ComClass(ClsLwPolylineVertex.ClassId, ClsLwPolylineVertex.InterfaceId, ClsLwPolylineVertex.EventsId)>
Public Class ClsLwPolylineVertex

#Region "COM GUID"
    ' 这些 GUID 提供此类的 COM 标识 
    ' 及其 COM 接口。若更改它们，则现有的
    ' 客户端将不再能访问此类。
    Public Const ClassId As String = "3869cf78-4e23-49b4-b7fb-eafe522f4ba0"
    Public Const InterfaceId As String = "361b3edf-07be-4186-b6ef-9de78b39e8d3"
    Public Const EventsId As String = "e5e33853-e1b7-441a-82d9-d292cc2fa828"
#End Region

    ' 可创建的 COM 类必须具有一个不带参数的 Public Sub New() 
    ' 否则， 将不会在 
    ' COM 注册表中注册此类，且无法通过
    ' CreateObject 创建此类。
    Public Sub New()
        MyBase.New()
    End Sub


    Public Sub New(Optional _x As Double = 0#, Optional _y As Double = 0#, Optional b As Double = 0#)
        Call Creator(_x, _y, b)
    End Sub

#Region "属性和字段"
    Private _location As ClsPoint2d
    Public Property Position() As ClsPoint2d
        Get
            Return _location
        End Get
        Set(ByVal value As ClsPoint2d)
            _location = value
        End Set
    End Property
    Private _bulge As Double
    Public Property Bulge() As Double
        Get
            Return _bulge
        End Get
        Set(ByVal value As Double)
            _bulge = value
        End Set
    End Property
    Public ReadOnly Property HasBulge() As Boolean
        Get
            Return Math.Abs(_bulge) > 0.00000001
        End Get

    End Property

#End Region

#Region "构造函数"
    Public Sub Creator(pt As ClsPoint2d, Optional b As Double = 0)
        Me.Bulge = b
        Me.Position = pt
    End Sub
    Public Sub Creator(x As Double, y As Double, Optional b As Double = 0)
        Me.Bulge = b
        Me.Position = New ClsPoint2d With {.X = x, .Y = y}
    End Sub


#End Region

#Region "方法"
    Public Function IsEqualTo(vertex As ClsLwPolylineVertex) As Boolean
        Dim m As New ClsMath
        Return m.IsEqual(Me.Bulge, vertex.Bulge) And Me.Position.IsEqualTo(vertex.Position)
    End Function
#End Region

#Region "Clone"
    Public Function Clone() As ClsLwPolylineVertex

        Dim t As Type = Me.GetType()
        Dim setProps As List(Of PropertyInfo) = t.GetProperties.Where(Function(p) p.CanWrite).ToList()
        Dim rtnObj = Activator.CreateInstance(t)
        For Each p As PropertyInfo In setProps
            p.SetValue(rtnObj, p.GetValue(Me, Nothing), Nothing)
        Next
        Return DirectCast(rtnObj, ClsLwPolylineVertex)

    End Function

#End Region

End Class


